/*
 *
 *  Connection Manager
 *
 *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef __CONNMAN_NETWORK_H
#define __CONNMAN_NETWORK_H

#include <connman/types.h>
#include <connman/device.h>
#include <connman/element.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * SECTION:network
 * @title: Network primitives
 * @short_description: Functions for handling networks
 */

enum connman_network_type {
	CONNMAN_NETWORK_TYPE_UNKNOWN       = 0,
	CONNMAN_NETWORK_TYPE_WIFI          = 1,
	CONNMAN_NETWORK_TYPE_WIMAX         = 2,
	CONNMAN_NETWORK_TYPE_BLUETOOTH_PAN = 8,
	CONNMAN_NETWORK_TYPE_BLUETOOTH_DUN = 9,
	CONNMAN_NETWORK_TYPE_CELLULAR      = 10,
	CONNMAN_NETWORK_TYPE_VENDOR        = 10000,
};

enum connman_network_protocol {
	CONNMAN_NETWORK_PROTOCOL_UNKNOWN = 0,
	CONNMAN_NETWORK_PROTOCOL_IP      = 1,
	CONNMAN_NETWORK_PROTOCOL_PPP     = 2,
};

enum connman_network_activation_state {
	CONNMAN_NETWORK_ACTIVATION_STATE_UNKNOWN = 0,
	CONNMAN_NETWORK_ACTIVATION_STATE_ACTIVATED = 1,
	CONNMAN_NETWORK_ACTIVATION_STATE_ACTIVATING = 2,
	CONNMAN_NETWORK_ACTIVATION_STATE_PARTIALLY_ACTIVATED = 3,
	CONNMAN_NETWORK_ACTIVATION_STATE_NOT_ACTIVATED = 4,
};

enum connman_network_cellular_technology {
	CONNMAN_NETWORK_TECHNOLOGY_UNKNOWN = 0,
	CONNMAN_NETWORK_TECHNOLOGY_1XRTT = 1,
	CONNMAN_NETWORK_TECHNOLOGY_EVDO = 2,
	CONNMAN_NETWORK_TECHNOLOGY_GPRS = 3,
	CONNMAN_NETWORK_TECHNOLOGY_EDGE = 4,
	CONNMAN_NETWORK_TECHNOLOGY_UMTS = 5,
	CONNMAN_NETWORK_TECHNOLOGY_HSPA = 6,
	CONNMAN_NETWORK_TECHNOLOGY_HSPA_PLUS = 7,
	CONNMAN_NETWORK_TECHNOLOGY_LTE = 8,
	CONNMAN_NETWORK_TECHNOLOGY_LTE_ADVANCED = 9,
	CONNMAN_NETWORK_TECHNOLOGY_GSM = 10,
};

enum connman_network_cellular_roaming_state {
	CONNMAN_NETWORK_ROAMING_STATE_UNKNOWN = 0,
	CONNMAN_NETWORK_ROAMING_STATE_HOME = 1,
	CONNMAN_NETWORK_ROAMING_STATE_ROAMING = 2
};

enum connman_network_phymode {
	CONNMAN_NETWORK_PHYMODE_UNDEF	= 0,	/* Unknown/undefined */
	CONNMAN_NETWORK_PHYMODE_11A	= 1,	/* 802.11a */
	CONNMAN_NETWORK_PHYMODE_11B	= 2,	/* 802.11b */
	CONNMAN_NETWORK_PHYMODE_11G	= 3,	/* 802.11g */
	CONNMAN_NETWORK_PHYMODE_11N	= 4,	/* 802.11n */
	CONNMAN_NETWORK_PHYMODE_HALF	= 5,	/* PSB Half-width */
	CONNMAN_NETWORK_PHYMODE_QUARTER	= 6,	/* PSB Quarter-width */
	CONNMAN_NETWORK_PHYMODE_TURBO	= 7,	/* Atheros Turbo mode */

	CONNMAN_NETWORK_PHYMODE_MAX
};

struct connman_network;

struct connman_network *connman_network_create(const char *identifier,
					enum connman_network_type type);
struct connman_network *connman_network_ref(struct connman_network *network);
void connman_network_unref(struct connman_network *network);

void connman_network_set_error(struct connman_network *network,
				enum connman_element_error error);

enum connman_network_type connman_network_get_type(struct connman_network *network);
const char *connman_network_get_identifier(struct connman_network *network);

const char *connman_network_get_path(struct connman_network *network);
void connman_network_set_index(struct connman_network *network, int index);
int connman_network_get_index(struct connman_network *network);

void connman_network_set_protocol(struct connman_network *network,
					enum connman_network_protocol protocol);
void connman_network_set_group(struct connman_network *network,
						const char *group);
const char *connman_network_get_group(struct connman_network *network);

int connman_network_set_available(struct connman_network *network,
						connman_bool_t available);
connman_bool_t connman_network_get_available(struct connman_network *network);
int connman_network_set_associating(struct connman_network *network);
int connman_network_set_connected(struct connman_network *network);
int connman_network_set_connecting(struct connman_network *network);
int connman_network_restart_connect_timer(struct connman_network *network);
int connman_network_set_disconnected_only(struct connman_network *network);
int connman_network_set_disconnected(struct connman_network *network);
int connman_network_set_disconnecting(struct connman_network *network);
connman_bool_t connman_network_get_connected(struct connman_network *network);
connman_bool_t connman_network_get_associating(struct connman_network *network);
connman_bool_t connman_network_get_previously_connected(
					struct connman_network *network);
connman_bool_t connman_network_get_in_use(struct connman_network *network);

int connman_network_set_address(struct connman_network *network,
				const void *address, unsigned int size);
int connman_network_set_name(struct connman_network *network,
							const char *name);
connman_uint8_t connman_network_get_strength(struct connman_network *network);
int connman_network_set_strength(struct connman_network *network,
						connman_uint8_t strength);

int connman_network_set_string(struct connman_network *network,
					const char *key, const char *value);
const char *connman_network_get_string(struct connman_network *network,
							const char *key);
int connman_network_set_uint8(struct connman_network *network,
					const char *key, connman_uint8_t value);
connman_uint8_t connman_network_get_uint8(struct connman_network *network,
							const char *key);
int connman_network_set_uint16(struct connman_network *network,
					const char *key, connman_uint16_t value);
connman_uint16_t connman_network_get_uint16(struct connman_network *network,
							const char *key);
void connman_network_set_phymode(struct connman_network *network,
					enum connman_network_phymode phymode);
enum connman_network_phymode connman_network_get_phymode(struct connman_network
							*network);
const char *connman_network_get_phymode_name(enum connman_network_phymode);
void connman_network_set_scangen(struct connman_network *network, int scangen);
int connman_network_get_scangen(struct connman_network *network);
int connman_network_set_blob(struct connman_network *network,
			const char *key, const void *data, unsigned int size);
const void *connman_network_get_blob(struct connman_network *network,
					const char *key, unsigned int *size);
char *connman_network_get_hex_ssid(struct connman_network *network);

struct connman_device *connman_network_get_device(struct connman_network *network);

void *connman_network_get_data(struct connman_network *network);
void connman_network_set_data(struct connman_network *network, void *data);


struct connman_network_operator {
	char *code;
	char *name;
	char *country;
};

void connman_network_set_operator(struct connman_network *network,
                                  struct connman_network_operator *op);
void connman_network_set_olp_url(struct connman_network *network,
				 const char *olp_url,
				 const char *olp_method,
				 const char *olp_postdata);
void connman_network_set_usage_url(struct connman_network *network,
				   const char *usage_url);

void connman_network_set_registration_info(
		struct connman_network *network,
		enum connman_network_cellular_technology network_technology,
		enum connman_network_cellular_roaming_state roaming_state);

void connman_network_set_activation_state(struct connman_network *network,
			enum connman_network_activation_state activation_state,
			enum connman_element_error err);

struct connman_network_apn {
	char *network_id;
	char *apn;
	char *username;
	char *password;
	char *name;
	char *localized_name;
	char *language;
};

const struct connman_network_apn *connman_network_get_apn(
		struct connman_network *network);
void connman_network_save_last_good_apn(struct connman_network *network,
					const struct connman_network_apn *apn);
const struct connman_network_apn *connman_network_get_last_good_apn(
		struct connman_network *network);

int connman_network_get_peer_count(struct connman_network *network);

enum connman_network_cellular_roaming_state
	connman_network_get_roaming_state(struct connman_network *network);

struct connman_network_driver {
	const char *name;
	enum connman_network_type type;
	int priority;
	int (*probe) (struct connman_network *network);
	void (*remove) (struct connman_network *network);
	int (*connect) (struct connman_network *network);
	int (*disconnect) (struct connman_network *network);

	int (*activate_cellular_network) (struct connman_network *network,
		const char *carrier);
};

int connman_network_driver_register(struct connman_network_driver *driver);
void connman_network_driver_unregister(struct connman_network_driver *driver);

/*
 * Convert from a possibly binary id to a textual name; allocate space
 * if no buffer is provided.
 */
char *connman_network_get_name_from_id(const unsigned char *id,
				       unsigned int id_len,
				       char *result,
				       unsigned int result_size);

#ifdef __cplusplus
}
#endif

#endif /* __CONNMAN_NETWORK_H */
